/*
 ============================================================================
 Name		: FbList.h
 Author	  : ceze
 Version	 :
 Copyright   : FlashBox for ver.Zhongyou(???)
 Description : CFbList Flashbox 动态列表
 ============================================================================
 */

#ifndef FBLIST_H
#define FBLIST_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <coecntrl.h>
#include <eikscrlb.h>
#include <eiksbobs.h> 

// CLASS DECLARATION
class CFbListData;
class CFbList;

//FbList 事件定义
enum TFbListEventType
{
	EMakeVisibleTrue = 0x100,
	EMakeVisibleFalse,
	EItemFocusedChange,
	EItemSelected,
	EPageSingl,		//独立页面
	EPageMultFirst, //
	EPageMultMiddle,
	EPageMultLast,
	EItemDelete,
	EPageLocal,
	EPageRemote
};

//列表类型
enum TFbListStyle
{
	EStyleDataList = 0, //普通形
	EStyleDefault = EStyleDataList,
	EStyleOptionMenu //option菜单形
};

//事件监听
class MListObserver
{
public:
	/**
	 * pHandle 发出消息的对象
	 * aItemIndex:激活的item 序号
	 * aItemID : 激活的item id
	 * aEventType:事件类型
	 */
	virtual void ListItemEvent (CFbList *pHandle, TInt aItemIndex, TInt aItemID, TInt aEventType ) = 0;
};

//
/**
 *  CFbList
 * 
 */
class CFbList : public CCoeControl /*, MEikScrollBarObserver*/
{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	virtual ~CFbList ();

	/**
	 * Two-phased constructor.
	 */
	static CFbList* NewL (const TRect &aRect, CCoeControl *pParent ,const TFbListStyle style = EStyleDefault);

	/**
	 * Two-phased constructor.
	 */
	static CFbList* NewLC (const TRect &aRect, CCoeControl *pParent, const TFbListStyle style);

public:
	/**
	 * 添加列表项
	 * aIndex加入位置, 默认添加到最后
	 */
	void AddItemL(CFbListData *pItemData, const TInt aIndex = -1);
	
	/**
	 * 删除指定列表项
	 */
	void RemoveItem(const TInt aIndex);
	
	/**
	 * 删除所有列表项
	 */
	void RemoveAll();
	
	/**
	 * List
	 */	void SetBackground(const TRgb &aFrameRgb, const TRgb &aBackRgb, const TInt &aResId = 0);
	
	/**
	 * focused background
	 */
	void SetFocusedBackground(const TRgb &aRgb, const TInt &aResId = 0);
	
	/**
	 * Next Page
	 */
	//void NextPage();
	
	/**
	 * Prev page
	 */
	//void PrevPage();
	
	/**
	 * next page
	 */
	void NextListPage ();

	/**
	 * Prev page
	 */
	void PrevListPage ();
	
	/**
	 * 设置文本颜色
	 */
	void SetTextColor(const TRgb &aTextRgb, const TRgb &aFocusedTextRgb);

	/**
	 * 设置消息监听接口
	 */
	void SetObserver(MListObserver *pObserver);
	
	/**
	 * 通过itemIndex获取列表项
	 */
	CFbListData *GetListItem (const TInt itemIndex );

	/**
	 * 获取焦点所在位置
	 */
	TInt GetFocusedIndex ();
		
	/**
	 * 判断传入的项id是否存在
	 * 返回值,-1不存在, 其它所在位置序号
	 */
	TInt IndexByItmeId(const TInt itemId);
	
	/**
	 * from CCoeControl
	 */
	void MakeVisible(TBool aVisible);
	
	/*
	 * From CoeControl,
	 * 按键事件接收处理
	 */
	TKeyResponse OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType );
	
	/*
	 * 更新(获取)页面显示状态
	 */
	void UpdatePageSatuse();

	TInt GetFocusItemPosY();
	
private:
	
	/**
	 * Constructor for performing 1st stage construction
	 */
	CFbList (const TFbListStyle style);

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL (const TRect &aRect, CCoeControl *pParent );

	/**
	 * From CoeControl,SizeChanged.
	 */
	void SizeChanged ();

	/**
	 * From CoeControl,CountComponentControls.
	 */
	TInt CountComponentControls () const;

	/**
	 * From CCoeControl,ComponentControl.
	 */
	CCoeControl* ComponentControl (TInt aIndex ) const;

	
	/**
	 * From CCoeControl,Draw.
	 */
	void Draw (const TRect& aRect ) const;
	
	/**
	 * from MEikScrollBarObserver
	 */
	//void HandleScrollEventL(CEikScrollBar *  aScrollBar,  TEikScrollEvent  aEventType);
	
	/**
	 * 
	 */
	TInt CurrentPageIndex();
	
	/**
	 * 刷屏回调函数
	 */
	static TInt DrawCallback(TAny* pInst);

private:
	//List项数组
	CArrayPtrFlat<CFbListData> 	*m_pListArray;//数据项数组	
	TInt 						m_indexFocused;//当前页面焦点所在位置
	TInt						m_maxItemsShow;//item count per page
	TInt 						m_pageIndex;//所再页面位置
	MListObserver 				*m_pObserver;//事件监听接口对象 not need to delete
	
	//background 
	TRgb						m_rgbFrame;
	TRgb						m_rgbBack;
	CFbsBitmap					*m_pBackImg;
	//icon
	CFbsBitmap					*m_pDefaultIcon;
	
	//focused background
	TRgb 						m_rgbFocusedBack;
	CFbsBitmap					*m_pFocusedBackImg;
	
	//滚动条
	//CEikScrollBar 				*m_pScrollBar;
	//text color
	TRgb						m_rgbText;
	TRgb						m_rgbFocusedText;
	//
	
	CFont						*m_pFont; //not need to delete
	//样式
	TFbListStyle				m_style;
	TRect						m_initRect;
	
	//控制文字滚动	
	CPeriodic					*m_pPeriodic;		
	//TInt 						m_textWidth;
	TInt 						m_textOffset;
};

#endif // FBLIST_H
